initEditor()
var $image=$('#image')
var option={
    aspectRatio: 400 / 280,
    preview: '.img-preview'
}
$image.cropper(option)
var form=layui.form;
$('#aa').on('click',function(){
    $('#file').trigger('click')
})



$('#file').on('change',function(){
    if(this.isDefaultNamespace.length>0);
    var fileObj=this.files[0];
    var url=URL.createObjectURL(fileObj);
    $image.cropper('destroy').attr('src', url).cropper(option)
    
})



$.ajax({
    url:'/my/category/list',
    success:function(res){
        var html=template('tpl-category', res);
        $('select').html(html);
        form.render('select')

    }
})



$('form').on('submit',function(e){
    e.preventDefault()
 var data=   new FormData(this)

 data.set('content',tinyMCE.activeEditor.getContent())
 var canvas=$image.cropper('getCroppedCanvas',{
     width:400,
     height:280
 })
canvas.toBlob(function(blob){
    data.append('cover_img',blob) 
    data.forEach(function(value, k){
    console.log(value ,k);
})
    $.ajax({
        type: 'POST',
        url: '/my/article/add',
        data: data,
        // 提交的formdata对象,所以必须添加下面两项
        contentType: false,
        processData: false,
        success: function (res) {
            layer.msg(res.message)
           
            if (res.status == 0) {
                location.href = '../article/shancu.html'
            }
        }
    })
    
})
})
